//
//  ShareManager.m
//  GolfFriend
//
//  Created by Vescky on 14-5-18.
//  Copyright (c) 2014年 vescky.org. All rights reserved.
//

#import "ShareManager.h"
#import "SVProgressHUD.h"
#import "AppDelegate.h"

@implementation ShareManager

ShareManager *gfShareManager;

+ (id)shareManeger {
    if (!gfShareManager) {
        gfShareManager = [[ShareManager alloc] init];
    }
    return gfShareManager;
}

- (void)shareToSocialPlatformWithUrl:(NSString*)_url title:(NSString*)_stitle text:(NSString*)_text image:(UIImage*)_image parrentViewController:(UIViewController*)parrentVc {
    if ([_image isEqual:Default_Image_Normal]) {
        _image = [UIImage imageNamed:@"logo_circle.png"];
    }
    if ([_url stringByMatching:@"html"]) {
        _url = [_url stringByReplacingOccurrencesOfString:@".html" withString:@"Share.html"];
    }
    else {
        _url = [_url stringByReplacingOccurrencesOfString:@"?" withString:@"Share?"];
    }
    [UMSocialWechatHandler setWXAppId:Wechat_Key url:_url];
    [UMSocialData defaultData].extConfig.wechatSessionData.title = _stitle;
    [UMSocialSnsService presentSnsIconSheetView:parrentVc
                                         appKey:UMSocial_Key
                                      shareText:_text
                                     shareImage:_image
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatTimeline,UMShareToWechatSession,UMShareToEmail,nil]
                                       delegate:self];
}

-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        //        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
        [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"分享到%@成功!",[[response.data allKeys] objectAtIndex:0]]];
    }
    else if (response.responseCode == UMSResponseCodeBaned) {
        [SVProgressHUD showErrorWithStatus:@"分享失败，您的账户已被封禁！"];
    }
    else if (response.responseCode == UMSResponseCodeShareRepeated) {
        [SVProgressHUD showErrorWithStatus:@"分享失败：发送内容为空！"];
    }
    else if (response.responseCode == UMSResponseCodeGetNoUidFromOauth) {
        [SVProgressHUD showErrorWithStatus:@"分享失败：分享内容重复！"];
    }
    else {
        [SVProgressHUD showErrorWithStatus:@"分享失败"];
    }
    
    NSLog(@"%d",response.responseCode);
    
    //    UMSResponseCodeBaned              = 505,        //用户被封禁
    //    UMSResponseCodeFaild              = 510,        //发送失败（由于内容不符合要求或者其他原因）
    //    UMSResponseCodeEmptyContent       = 5007,       //发送内容为空
    //    UMSResponseCodeShareRepeated      = 5016,       //分享内容重复
    //    UMSResponseCodeGetNoUidFromOauth  = 5020,       //授权之后没有得到用户uid
    //    UMSResponseCodeAccessTokenExpired = 5027,       //token过期
    //    UMSResponseCodeNetworkError       = 5050,       //网络错误
    //    UMSResponseCodeGetProfileFailed   = 5051,       //获取账户失败
    //    UMSResponseCodeCancel             = 5052,        //用户取消授权
    //    UMSResponseCodeNoApiAuthority
}


@end
